package com.grm.workflow.utils;

import cn.hutool.core.util.ObjectUtil;
import com.grm.common.utils.JwtUtil;
import com.grm.sys.mapper.SysUserMapper;
import com.grm.sys.mapper.SysUserRoleMapper;
import com.grm.sys.model.SysUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

@Component
public class TaskUtils {
    @Autowired
    private JwtUtil jwtUtil;
    @Autowired
    private SysUserMapper sysUserMapper;

    @Autowired
    private SysUserRoleMapper sysUserRoleMapper;

    /**
     * 获取用户组信息
     *
     * @return candidateGroup
     */
    public List<String> getCandidateGroup() {
        Long userId = jwtUtil.getUserId();
        SysUser sysUser = sysUserMapper.queryById(userId);
        List<Long> roleIds = sysUserRoleMapper.queryRoleIds(userId);
        // 查询用户角色、部门
        List<String> list = new ArrayList<>();
        if (ObjectUtil.isNotEmpty(roleIds)) {
            roleIds.forEach(roleId -> list.add("ROLE" + roleId));
        }
        if (ObjectUtil.isNotNull(sysUser.getDeptId())) {
            list.add("DEPT" + sysUser.getDeptId());
        }
        return list;
    }
}
